<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$setting=$this->setting;
$return['banner']=$setting['hdps'];
$return['setting']=$setting;
if($_RQ['op']=='main'){
	
	exi($return);
}
/*******op*******/
if($_RQ['op']=='list'){
	//查询进入该页面的客户所有订单
	$params=array('merchid'=>$_SESSION['onemerchid'],'user_id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']);
	if(isset($_RQ['status'])&& $_RQ['status'] != 10){
		$params['status']=intval($_RQ['status']);
		$return['status']=$_RQ['status'];
	}else{
		$return['status']=10;
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$order_list=pdo_getslice('jy_baoming_order',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($order_list){
		foreach($order_list as &$item){
			$member=pdo_get('core_members',array('id'=>$item['user_id'],'uniacid'=>$_SESSION['uniacid']));
			$activity=pdo_get('jy_baoming_list',array('id'=>$item['activity_id'],'uniacid'=>$_SESSION['uniacid']));
			$item['user_name']=$user['name'];
			$item['user_mobile']=$user['mobile'];
			$item['activity']=$activity;
			$item['createtime']=date('Y-m-d H:i:s', $item['createtime']);
			if($item['time']<time()){
				$item['canreceive']=1;
			}
		}
	}
	$return['list']=$order_list;
	exi($return);
}
//订单详情
if($_RQ['op']=='detail'){
	if(!$_RQ['id']){
	exi('订单不存在，请重新选择','error');
	}
	$order=pdo_get('jy_baoming_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	//用户信息
	$member=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['user_id']));
	//活动信息
	$activity=pdo_get('jy_baoming_list',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['activity_id']));	
	$order['diyfrom']=json_decode($order['diyfrom'],true);
	$order['members']=$order['members']?json_decode($order['members'],true):array();
	if(!$order['members']){
		$order['members'][]=array('diyfields'=>$order['diyfrom']);
	}
	if($order['members']){
		foreach($order['members'] as &$mv){
			foreach($mv['diyfields'] as &$v){
				if(($v['type']==4 || $v['type']==5)  && $v['data']){
					$v['data'] = explode(";", $v['data']);
				}
			}
		}
	}
	if($order['time']<time()){
		$order['canreceive']=1;
	}
	$return['order']=$order;
	$return['member']=$member;
	$return['activity']=$activity;
	exi($return);
}
if($_RQ['op']=='receive'){
	if(!$_RQ['id']){
		exi('报名订单不存在，请重新选择订单','error');
	}
	$order=pdo_get('jy_baoming_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	if($order['time']>time()){
		exi('活动时间还未到，不能确认完成！','error');
	}
	pdo_update('jy_baoming_order',array('status'=>'4'),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));	
	exi('确认服务成功');
}
if($_RQ['op']=='del'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择订单','error');
	}
	pdo_delete('jy_baoming_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	exi('删除报名成功');
}
if($_RQ['op']=='pay'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择订单','error');
	}
	$pay_id=pdo_getcolumn('jy_baoming_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']),'pay_id');
	exi($pay_id);
}